package com.atguigu.yygh.msm.service.impl;

import com.atguigu.yygh.common.util.HttpUtils;
import com.atguigu.yygh.msm.service.MsmService;
import com.atguigu.yygh.vo.msm.MsmVo;
import org.apache.http.HttpResponse;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * @program: yygh_parent
 * @author: Mr.Zhuo
 * @create: 2022-03-14 17:30
 **/
@Service
public class MsmServiceImpl implements MsmService {
    // 发送短信
    @Override
    public Boolean sendCode(String phone, String code) {

        String host = "http://dingxin.market.alicloudapi.com";
        String path = "/dx/sendSms";
        String method = "POST";
        String appcode = "110bc424ecf14e0ea7ad04c46ad89675";
        Map<String, String> headers = new HashMap<String, String>();
        //Authorization:APPCODE 83359fd73fe94948385f570e3c139105
        headers.put("Authorization", "APPCODE " + appcode);
        Map<String, String> querys = new HashMap<String, String>();
        querys.put("mobile", phone);
        querys.put("param", "code:" + code);
        querys.put("tpl_id", "TP1711063");
        Map<String, String> bodys = new HashMap<String, String>();
        try {
            HttpResponse response = HttpUtils.doPost(host, path, method, headers,
                    querys, bodys);
            System.out.println(response.toString());
            return true;
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }

    @Override
    public void sendMq(MsmVo msmVo) {
        System.out.println("发送成功预约的消息给号码："+msmVo.getPhone());
    }
}
